package com.zhangh.summer.admin.controller.user;

import com.zhangh.summer.admin.biz.menu.MenuBiz;
import com.zhangh.summer.admin.biz.user.UserBiz;
import com.zhangh.summer.admin.model.bo.*;
import com.zhangh.summer.admin.model.po.AdUserPO;
import com.zhangh.summer.admin.support.base.JsonResponse;
import com.zhangh.summer.admin.support.ds.common.pager.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author: zhanghui  zhanghlucky@163.com
 * @create: 2021-10-08 22:56
 **/
@RestController
@RequestMapping(value = "/user",method = RequestMethod.POST)
public class UserController {

    @Autowired
    private UserBiz userBiz;
    @Autowired
    private MenuBiz menuBiz;

    @RequestMapping("/dataPager")
    public String dataPager(@RequestBody UserQuery query) {
        DataPager<UserBO> dataPager=this.userBiz.getUserDataPager(query,query.getPager());
        return new JsonResponse().toJson(dataPager);
    }

    @RequestMapping("/getUser/{id}")
    public String getUser(@PathVariable Long id) {
        UserBO userBO=this.userBiz.getUserBO(id);
        return new JsonResponse().toJson(userBO);
    }

    @RequestMapping("/getNewUser")
    public String getNewUser() {
        UserBO userBO=this.userBiz.getUserBO(0L);
        return new JsonResponse().toJson(userBO);
    }

    @RequestMapping("/save")
    public String save(@RequestBody UserBO userBO) {
        long c1=this.userBiz.saveUser(userBO);
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/update")
    public String update(@RequestBody UserBO userBO) {
        int c1=this.userBiz.updateUser(userBO);
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/delete")
    public String delete(@RequestBody DataBO dataBO) {
        int c1=this.userBiz.deleteUser(dataBO.getId());
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/getUserAuthMenu/{id}")
    public String getUserAuthMenu(@PathVariable Long id) {
        List<MenuBO> menuBOList=this.menuBiz.getUserAuthMenuList(id);
        return new JsonResponse().toJson(menuBOList);
    }

    @RequestMapping("/validateLoginName")
    public String validateLoginName(@RequestBody NoValidatorBO noValidatorBO) {
        boolean bl=this.userBiz.validateLoginName(noValidatorBO);
        return new JsonResponse().toJson(bl);
    }

    @RequestMapping("/getCurrentUser")
    public String getCurrentUser() {
        AdUserPO adUserPO =this.userBiz.getCurrentUser();
        adUserPO.setLoginPwd(null);
        return new JsonResponse().toJson(adUserPO);
    }

    @RequestMapping("/updatePwd")
    public String updatePwd(@RequestBody UserBO userBO) {
        int c1=this.userBiz.updatePwd(userBO);
        return new JsonResponse().toJson(c1);
    }






}
